#include "StdAfx.h"
#include "SimpleInfo.h"

SimpleInfoCommander::SimpleInfoCommander(void)
{
}

SimpleInfoCommander::~SimpleInfoCommander(void)
{
}

int SimpleInfoCommander::ProcessCommand( void )
{
	if (!m_OnlineStatus.isOnline())
	{
		return COMMAND_INVALID_CONN;
	}
	CMarkup xmlSimpleInfo;
	xmlSimpleInfo.AddElem(_T("IPIN"));
	xmlSimpleInfo.AddChildElem(_T("Type"), CLIENT_SIMPLE_INFO);
	xmlSimpleInfo.AddChildElem(_T("Info"));
	xmlSimpleInfo.IntoElem();
	if (m_UserName.find('@'))
	{
		xmlSimpleInfo.AddChildElem(_T("Email"), m_UserName.c_str());
	}else
	{
		xmlSimpleInfo.AddChildElem(_T("UID"), m_UserName.c_str());
	}

	m_Command = xmlSimpleInfo.GetDoc();
	int ConnRsp = SendCommand();
	if (ConnRsp != CONNECTION_OK)
	{
		return COMMAND_CONN_ERROR;
	}
	// Write response to global variable
	CMarkup xmlInfo;
	if (xmlInfo.SetDoc(m_Reply.c_str()))
	{
		xmlInfo.FindElem(_T("IPIN"));
		xmlInfo.IntoElem();
		xmlInfo.FindElem(_T("Type"));
		if (_wtoi(xmlInfo.GetData()) != SERVER_USERINFO)
		{
			return COMMAND_SERVER_INTERNAL_ERROR;
		}
		xmlInfo.FindElem(_T("Info"));
		xmlInfo.IntoElem();
		xmlInfo.FindElem(_T("Name"));
		gUserInfo.m_UserName = xmlInfo.GetData();
		xmlInfo.FindElem(_T("Email"));
		gUserInfo.m_Email = xmlInfo.GetData();
		xmlInfo.FindElem(_T("UID"));
		gUserInfo.m_UID = xmlInfo.GetData();
	}

	

	return COMMAND_OK;
}